import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

// 定义自定义注解 @GuageAutowired
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@interface GuageAutowired {
}

// 模拟一个简单的 Bean 容器
class BeanContainer {
    private static final Map<Class<?>, Object> beans = new HashMap<>();

    public static <T> void registerBean(Class<T> clazz, T bean) {
        beans.put(clazz, bean);
    }

    public static Object getBean(Class<?> clazz) {
        return beans.get(clazz);
    }
}

// 模拟依赖注入功能
class GuageAutowiredProcessor {
    public static void process(Object target) {
        Class<?> clazz = target.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (field.isAnnotationPresent(GuageAutowired.class)) {
                field.setAccessible(true);
                Class<?> fieldType = field.getType();
                Object bean = BeanContainer.getBean(fieldType);
                if (bean != null) {
                    try {
                        field.set(target, bean);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

// 定义一个服务接口
interface UserService {
    void sayHello();
}

// 实现服务接口
class UserServiceImpl implements UserService {
    @Override
    public void sayHello() {
        System.out.println("Hello, World!");
    }
}

// 定义一个需要依赖注入的类
class UserController {
    @GuageAutowired
    private UserService userService;

    public void doSomething() {
        if (userService != null) {
            userService.sayHello();
        }
    }
}

public class GuageAutowiredAnnotationExample {
    public static void main(String[] args) {
        // 注册 Bean
        UserService userService = new UserServiceImpl();
        BeanContainer.registerBean(UserService.class, userService);

        // 创建需要注入依赖的对象
        UserController userController = new UserController();

        // 进行依赖注入
        GuageAutowiredProcessor.process(userController);

        // 调用方法测试
        userController.doSomething();
    }
}    